package models;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import play.data.validation.Password;
import play.data.validation.Required;
import siena.*;

public class User extends Model{

	@Id(Generator.AUTO_INCREMENT)
	private Long userId;
	@NotNull
	private String userName;
	@NotNull @Password
	private String password;
	@NotNull
	private Date dateOfBirth;
	@NotNull
	private String email;
	
	private Date created;
	private Date modified;
	private static int count = 0;
	
	public User(String name, String password, Date dateOfBirth, String email){
		super();
		this.userName = name;
		this.password = password;
		this.dateOfBirth = dateOfBirth;
		this.email = email;
		this.created = new Date();
		this.modified = this.created;
		count++;
	}
	
	public static Query<User> getAll(){
		return Model.all(User.class);
	}
	
	public static User findById(Long id){
		return getAll().filter("id", id).get();
	}
	public static List<User> findAllUsers(){
		return getAll().fetch();
	}
	
	public static User findByEmail(String email){
		
		return getAll().filter("email", email).get();
	}
	public String getName(){
		return this.userName;
	}
	
	public Long getId(){
		return this.userId;
	}

	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Date getDateOfBirth() {
		return dateOfBirth;
	}

	public void setDateOfBirth(Date dateOfBirth) {
		this.dateOfBirth = dateOfBirth;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public Date getCreated() {
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

	public Date getModified() {
		return modified;
	}

	public void setModified(Date modified) {
		this.modified = modified;
	}

	public static int getCount() {
		return count;
	}

	public static void setCount(int count) {
		User.count = count;
	}
}
